/*
 * Copyright 2010 Assert Developments
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package be.ad.coffeebreak.domain;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

/**
 * @author Stefan Bangels
 */
@Entity
@Table(name = "USERS", uniqueConstraints = {
        @UniqueConstraint(name = "USERS_EMAIL_IDX", columnNames = {"email"})}
)
@SequenceGenerator(name = "USER_SEQ", sequenceName = "USER_SEQ")
@NamedQueries(value = {
        @NamedQuery(name = User.QUERY_FIND_USER_BY_EMAIL,
                query = "SELECT u FROM User u WHERE u.email = :" + User.QUERY_PARAM_EMAIL),
        @NamedQuery(name = User.QUERY_FIND_ALL_USERS,
                query = "SELECT u FROM User u")
})
@XmlRootElement
public class User implements Serializable {

    // Queries
    public static final String QUERY_FIND_ALL_USERS = "User#findAllUsers";
    public static final String QUERY_FIND_USER_BY_EMAIL = "User#findUserByEmail";

    // Query parameters
    public static final String QUERY_PARAM_EMAIL = "email";

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USER_SEQ")
    private Long id;
    @NotNull
    @Column(unique = true, nullable = false)
    private String email;
    @NotNull
    @Column(nullable = false)
    private String name;
    private String country;
    private String language;
    private String timeZone;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = timeZone;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", email='" + email + '\'' +
                ", name='" + name + '\'' +
                ", country='" + country + '\'' +
                ", language='" + language + '\'' +
                ", timeZone='" + timeZone + '\'' +
                '}';
    }

}
